public class test {
    //leetcode 1020.飞地的数量
    class Solution {
        public int[] dx = {0,0,1,-1};
        public int[] dy = {1,-1,0,0};
        public Queue<int[]> queue;
        public int[][] nums;
        public boolean[][] count;
        public int row;
        public int col;
        public int numEnclaves(int[][] grid) {
            row = grid.length;
            col = grid[0].length;
            queue = new LinkedList<>();
            nums = new int[row][col];
            count = new boolean[row][col];
            int sum = 0;
            //正难则反,找到能走出去的边界岛屿即可
            for(int i=0;i<row;i++){
                for(int j=0;j<col;j++){
                    // 1. 查找边界节点
                    // 2. 以边界岛屿作为起点
                    if((i == 0 || i == row - 1 || j == 0 || j == col - 1) && grid[i][j] == 1){
                        queue.add(new int[]{i,j});
                        count[i][j] = true;
                    }
                    //统计所有1
                    if(grid[i][j] == 1){
                        sum++;
                    }
                }
            }
            // 记得也要算上初始边界岛屿数
            int wai = queue.size();
            // 查找所有边界岛屿
            while(!queue.isEmpty()){
                int[] t = queue.poll();
                for(int i = 0;i < 4;i++){
                    int x = t[0] + dx[i];
                    int y = t[1] + dy[i];
                    // 1. 保证x,y合法
                    // 2. 保证该地区为陆地
                    // 3. 保证该地区未被探索过
                    if(x >= 0 && x < row && y >= 0 && y < col && grid[x][y] == 1 && !count[x][y]){
                        count[x][y] = true;
                        queue.add(new int[]{x,y});
                        wai++;
                    }
                }
            }
            return sum - wai;
        }
    }
    //蓝桥杯 最大区间(⭐⭐⭐)
    public class Main {
        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            int n = in.nextInt();

            long[] arr = new long[n];
            int[] l = new int[n];
            int[] r = new int[n];
            Arrays.fill(l,-1);
            Arrays.fill(r,n);
            for(int i = 0;i < n;i++){
                arr[i] = in.nextLong();
            }
            Deque<Integer> deque = new ArrayDeque<>();
            for(int i = 0;i < n;i++){
                while(!deque.isEmpty() && arr[deque.peekLast()] >= arr[i]){
                    deque.pollLast();
                }
                if(!deque.isEmpty()){
                    l[i] = deque.peekLast();
                }
                deque.addLast(i);
            }
            for(int i = n - 1;i >= 0 ;i--){
                while(!deque.isEmpty() && arr[deque.peekLast()] >= arr[i]){
                    deque.pollLast();
                }
                if(!deque.isEmpty()){
                    r[i] = deque.peekLast();
                }
                deque.addLast(i);
            }
            long ans = 0;
            for(int i = 0;i <n;i++){
                ans = Math.max(1L * (r[i] - l[i] - 1) * arr[i],ans);
            }
            System.out.println(ans);
        }
    }
}
